package com.sf.fy.uav.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sf.fy.uav.common.enums.SettingStatusEnum;
import com.sf.fy.uav.entity.CouponActivity;
import com.sf.fy.uav.mapper.CouponActivityMapper;
import com.sf.fy.uav.service.ICouponActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 优惠券活动表 服务实现类
 * </p>
 *
 * @author LTQ
 * @since 2024-08-26
 */
@Service
public class CouponActivityServiceImpl extends ServiceImpl<CouponActivityMapper, CouponActivity> implements ICouponActivityService {

    @Autowired
    private CouponActivityMapper couponActivityMapper;


    @Override
    public CouponActivity getCouponActivity() {
        Date date = new Date();
        QueryWrapper<CouponActivity> couponActivityQueryWrapper = new QueryWrapper<>();
        couponActivityQueryWrapper.eq("deleted", false);
        couponActivityQueryWrapper.le("start_activity_time", date);
        couponActivityQueryWrapper.ge("end_activity_time", date);
        couponActivityQueryWrapper.ne("status", SettingStatusEnum.OFF.getStatus());
        couponActivityQueryWrapper.orderByDesc("create_time");
        couponActivityQueryWrapper.last("limit 1");
        return couponActivityMapper.selectOne(couponActivityQueryWrapper);
    }

    @Override
    public List<CouponActivity> selectNormalByBatchIds(List<String> ids) {
        QueryWrapper<CouponActivity> couponActivityQueryWrapper = new QueryWrapper<>();
        couponActivityQueryWrapper.eq("deleted", false);
        couponActivityQueryWrapper.notIn("status", Arrays.asList(SettingStatusEnum.OFF.getStatus(), SettingStatusEnum.ENDED.getStatus()));
        return couponActivityMapper.selectList(couponActivityQueryWrapper);
    }

}
